<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::Filter::ASCII85</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::Filter::ASCII85</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/filters/ascii_rb.html">
                origami/filters/ascii.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Class representing a filter used to <a
href="ASCII85.html#M000356">encode</a> and <a
href="ASCII85.html#M000357">decode</a> data written in base85 encoding.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000357">decode</a>&nbsp;&nbsp;
      <a href="#M000356">encode</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="../Filter.html">Filter</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000357" class="method-detail">
        <a name="M000357"></a>

        <div class="method-heading">
          <a href="#M000357" class="method-signature">
          <span class="method-name">decode</span><span class="method-args">(string)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decodes the given data encoded in base85.
</p>
<table>
<tr><td valign="top"><em>string</em>:</td><td>The data to <a href="ASCII85.html#M000357">decode</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000357-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000357-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters/ascii.rb, line 125</span>
125:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decode</span>(<span class="ruby-identifier">string</span>)
126:         
127:         <span class="ruby-identifier">input</span> = (<span class="ruby-identifier">string</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-constant">EOD</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">string</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">string</span>.<span class="ruby-identifier">index</span>(<span class="ruby-constant">EOD</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">string</span>).<span class="ruby-identifier">delete</span>(<span class="ruby-value str">&quot; \f\t\r\n\0&quot;</span>)
128:         
129:         <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
130:         <span class="ruby-identifier">result</span> = <span class="ruby-value str">&quot;&quot;</span>
131:         <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">do</span>
132:           
133:           <span class="ruby-identifier">outblock</span> = <span class="ruby-value str">&quot;&quot;</span>
134: 
135:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;z&quot;</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span>
136:             <span class="ruby-identifier">inblock</span> = <span class="ruby-value">0</span>
137:             <span class="ruby-identifier">codelen</span> = <span class="ruby-value">1</span>
138:           <span class="ruby-keyword kw">else</span>
139:             
140:             <span class="ruby-identifier">inblock</span> = <span class="ruby-value">0</span>
141:             <span class="ruby-identifier">codelen</span> = <span class="ruby-value">5</span>
142:             
143:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">5</span>
144:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidASCII85StringError</span>, <span class="ruby-value str">&quot;Invalid length&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
145:               
146:               <span class="ruby-identifier">addend</span> = <span class="ruby-value">5</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">input</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span>)
147:               <span class="ruby-identifier">input</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;u&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">addend</span>
148:             <span class="ruby-keyword kw">else</span>
149:               <span class="ruby-identifier">addend</span> = <span class="ruby-value">0</span>
150:             <span class="ruby-keyword kw">end</span>
151:           
152:             <span class="ruby-comment cmt"># Checking if this string is in base85</span>
153:             <span class="ruby-value">5</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span>
154:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;u&quot;</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">&quot;!&quot;</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span>
155:                 <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidASCII85StringError</span>, <span class="ruby-node">&quot;Invalid character sequence: #{input[i,5].inspect}&quot;</span>
156:               <span class="ruby-keyword kw">else</span>
157:                 <span class="ruby-identifier">inblock</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">-</span> <span class="ruby-value str">&quot;!&quot;</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span>) <span class="ruby-operator">*</span> <span class="ruby-value">85</span> <span class="ruby-operator">**</span> (<span class="ruby-value">4</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">j</span>)
158:               <span class="ruby-keyword kw">end</span>
159:             <span class="ruby-keyword kw">end</span>
160:           
161:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">inblock</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-value">32</span>
162:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidASCII85StringError</span>, <span class="ruby-node">&quot;Invalid value (#{inblock}) for block #{input[i,5].inspect}&quot;</span>
163:             <span class="ruby-keyword kw">end</span>
164:           
165:           <span class="ruby-keyword kw">end</span>
166:         
167:           <span class="ruby-value">4</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
168:             <span class="ruby-identifier">c</span> = <span class="ruby-identifier">inblock</span> <span class="ruby-operator">/</span> <span class="ruby-value">256</span> <span class="ruby-operator">**</span> (<span class="ruby-value">3</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p</span>)
169:             <span class="ruby-identifier">outblock</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">chr</span>
170:             
171:             <span class="ruby-identifier">inblock</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">*</span> <span class="ruby-value">256</span> <span class="ruby-operator">**</span> (<span class="ruby-value">3</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p</span>)
172:           <span class="ruby-keyword kw">end</span>
173:           
174:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">addend</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
175:             <span class="ruby-identifier">outblock</span> = <span class="ruby-identifier">outblock</span>[<span class="ruby-value">0</span>, <span class="ruby-value">4</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">addend</span>]
176:           <span class="ruby-keyword kw">end</span>
177:         
178:           <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">outblock</span>
179:           
180:           <span class="ruby-identifier">i</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">codelen</span>
181:         <span class="ruby-keyword kw">end</span>
182:         
183:         <span class="ruby-identifier">result</span>
184:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000356" class="method-detail">
        <a name="M000356"></a>

        <div class="method-heading">
          <a href="#M000356" class="method-signature">
          <span class="method-name">encode</span><span class="method-args">(stream)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Encodes given data into base85.
</p>
<table>
<tr><td valign="top"><em>stream</em>:</td><td>The data to <a href="ASCII85.html#M000356">encode</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000356-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000356-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters/ascii.rb, line 82</span>
 82:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encode</span>(<span class="ruby-identifier">stream</span>)
 83:         
 84:         <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
 85:         <span class="ruby-identifier">code</span> = <span class="ruby-value str">&quot;&quot;</span>
 86:         <span class="ruby-identifier">input</span> = <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">dup</span>
 87:         
 88:         <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">do</span>
 89:           
 90:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">4</span>
 91:             <span class="ruby-identifier">addend</span> = <span class="ruby-value">4</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">input</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">i</span>)
 92:             <span class="ruby-identifier">input</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">addend</span>
 93:           <span class="ruby-keyword kw">else</span>
 94:             <span class="ruby-identifier">addend</span> = <span class="ruby-value">0</span>
 95:           <span class="ruby-keyword kw">end</span>
 96:           
 97:           <span class="ruby-identifier">inblock</span> = (<span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">*</span> <span class="ruby-value">256</span><span class="ruby-operator">**</span><span class="ruby-value">3</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">*</span> <span class="ruby-value">256</span><span class="ruby-operator">**</span><span class="ruby-value">2</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">*</span> <span class="ruby-value">256</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">input</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-value">3</span>].<span class="ruby-identifier">ord</span>)
 98:           <span class="ruby-identifier">outblock</span> = <span class="ruby-value str">&quot;&quot;</span>
 99:           
100:           <span class="ruby-value">5</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
101:             <span class="ruby-identifier">c</span> = <span class="ruby-identifier">inblock</span> <span class="ruby-operator">/</span> <span class="ruby-value">85</span> <span class="ruby-operator">**</span> (<span class="ruby-value">4</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p</span>)
102:             <span class="ruby-identifier">outblock</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">&quot;!&quot;</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">c</span>).<span class="ruby-identifier">chr</span>
103:             
104:             <span class="ruby-identifier">inblock</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">*</span> <span class="ruby-value">85</span> <span class="ruby-operator">**</span> (<span class="ruby-value">4</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p</span>)
105:           <span class="ruby-keyword kw">end</span>
106:           
107:           <span class="ruby-identifier">outblock</span> = <span class="ruby-value str">&quot;z&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">outblock</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;!!!!!&quot;</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">addend</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
108:           
109:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">addend</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
110:             <span class="ruby-identifier">outblock</span> = <span class="ruby-identifier">outblock</span>[<span class="ruby-value">0</span>,(<span class="ruby-value">4</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">addend</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
111:           <span class="ruby-keyword kw">end</span>
112:           
113:           <span class="ruby-identifier">code</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">outblock</span>
114:           
115:           <span class="ruby-identifier">i</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">4</span>
116:         <span class="ruby-keyword kw">end</span>
117: 
118:         <span class="ruby-identifier">code</span>
119:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>